package Tests;

import org.jmock.Mockery;
import org.junit.Test;

import junit.framework.Assert;
import Core.Map.Tile;
import Core.Character;

public class TileTests
{
	@Test
	public void coordinateTest()
	{
		final int x = 5;
		final int y = 6;
		
		Tile tile = new Tile(x, y);
		
		Assert.assertEquals(x, tile.getX());
		Assert.assertEquals(y, tile.getY());
		
		tile.setX(10);
		tile.setY(3);
		
		Assert.assertEquals(10, tile.getX());
		Assert.assertEquals(3, tile.getY());
	}
	
	@Test
	public void cloneTest()
	{
		final int x = 3;
		final int y = 5;
		
		Tile original = new Tile(3, 5);
		
		Tile clone = original.clone();
		
		Assert.assertEquals(x, clone.getX());
		Assert.assertEquals(y, clone.getY());
	}
	
	@Test
	public void similarTilesTest()
	{
		Tile first = new Tile(0,0);
		Tile second = new Tile(1,1);
		
		Assert.assertTrue(first.isSimilarTo(second));
	}
	
	@Test
	public void tileCanHoldOneCharacter()
	{
		Mockery context = new Mockery();
		
		final Character character = context.mock(Character.class);
		
		Tile tile = new Tile(0, 0);
		
		tile.addCharacter(character);
		
		Assert.assertTrue(tile.containsCharacter(character));
	}
	
	@Test
	public void tileCanHoldMultipleCharacters()
	{
		Mockery context = new Mockery();
		
		final Character firstCharacter = context.mock(Character.class, "firstCharacter");
		final Character secondCharacter = context.mock(Character.class, "secondCharacter");
		
		Tile tile = new Tile(0, 0);
		
		tile.addCharacter(firstCharacter);
		tile.addCharacter(secondCharacter);
		
		Assert.assertTrue(tile.containsCharacter(firstCharacter));
		Assert.assertTrue(tile.containsCharacter(secondCharacter));
	}
	
	@Test
	public void tileCanRemoveCharacter()
	{
		Mockery context = new Mockery();
		
		final Character character = context.mock(Character.class);
		
		Tile tile = new Tile(0, 0);
		
		tile.addCharacter(character);
		tile.removeCharacter(character);

		Assert.assertFalse(tile.containsCharacter(character));
	}
}
